package com.forsythia.sns.action;

import com.forsythia.sns.Constants;
import com.forsythia.sns.to.UserTO;

public class LoginAction extends BaseAction {

    public String login() {
        UserTO user = login(passport, password);
        if (user != null) {
            if (useCookie) {
                getCookiesMap().put(Constants.COOKIE_PASSPORT, passport);
                getCookiesMap().put(Constants.COOKIE_PASSWORD, password);
            }
            return SUCCESS;
        }
        
        if (userService.isPassportExists(passport)) {
            addActionError(Constants.ERR_PASSPORT_NOT_EXISTS);
        } else {
            addActionError(Constants.ERR_PASSPORT_PASSWORD_NOT_MATCHED);
        }
        
        return ERROR;
    }

    // /////////////////////////////////////////////////////////////////////////////
    private String passport;
    private String password;
    private boolean useCookie;

    public boolean isUseCookie() {
        return useCookie;
    }

    public void setUseCookie(boolean useCookie) {
        this.useCookie = useCookie;
    }

    public String getPassport() {
        return passport;
    }

    public void setPassport(String passport) {
        this.passport = passport;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    // /////////////////////////////////////////////////////////////////////////////

    private static final long serialVersionUID = 8143422746366925388L;
}
